<!DOCTYPE html>
<%@page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
    <title>Summary report</title>
</head>

<body>
<h1 style="text-align: center">Monitoring Students Progress</h1>
<a href="<c:url value="/summaryreport"/>">Сводная ведомость</a>
<span>  |  </span><a href="<c:url value="/main"/>">Документация</a>
<span>  |  </span><a href="<c:url value="/documents/uploadworkload"/>">Загрузить нагрузку</a>
<span>  |  </span><a href="<c:url value="/logout"/>">Выход</a>

<c:if test="${groupsList.size() ne 0}">
    <form method="POST" action="<c:url value="/summaryreport/list"/>">
        Группа:
        <select name="groupName">
            <c:forEach var="groupName" items="${groupsList}">
                <option value="${groupName}"><c:out value="${groupName}"/></option>
            </c:forEach>
        </select>
        <input name="show" type="submit" value="Показать">
    </form>
    Выберите из списка группу, для которой нужно сформировать сводную ведомость.
</c:if>

<c:if test="${studentsList.size() ne 0}">

    <form method="POST" action="<c:url value="/summaryreport/save" />">
        <table border="1" style="text-align: center">
                <%-- header --%>

            <tr>
                <td rowspan="2">ФИО</td>
                <td rowspan="2">Отчислить</td>
                <c:forEach var="grade" items="${studentsList[0].gradeList}">
                    <td colspan="3">
                        <input type="hidden" name="disciplineList" value="${grade.disciplineName}"/>
                        <c:out value="${grade.disciplineName}"/>
                    </td>
                </c:forEach>
            </tr>
            <tr>
                <c:forEach var="grade" items="${studentsList[0].gradeList}">
                    <td> Оценка</td>
                    <td> Уваж.</td>
                    <td> Неуваж.</td>
                </c:forEach>
            </tr>

                <%-- details --%>
            <c:forEach var="student" items="${studentsList}">
                <tr>
                    <td>
                        <input type="hidden" name="id" value="${student.id}"/>
                        <c:out value="${student.name}"/>
                    </td>
                    <td>
                        <input type="checkbox" name="toExpelled" value="${student.id}"/>
                    </td>
                    <c:forEach var="grade" items="${student.gradeList}">
                        <td>
                            <select name="marks">

                                <c:forEach begin="0" end="10" step="1" var="mark">
                                    <option value="${mark}" <c:if
                                            test="${mark == grade.mark}"> selected </c:if>><c:out
                                            value="${mark}"/></option>
                                </c:forEach>

                                <c:forEach begin="1" end="5" step="1" var="mark">
                                    <option value="${mark*(-1)}" <c:if
                                            test="${mark*(-1) == grade.mark}"> selected </c:if>>
                                        <c:choose>
                                            <c:when test="${mark*(-1) == (-1)}"> зачтено </c:when>
                                            <c:when test="${mark*(-1) == (-2)}"> не аттестован </c:when>
                                            <c:when test="${mark*(-1) == (-3)}"> незачтено </c:when>
                                            <c:when test="${mark*(-1) == (-4)}"> не явился </c:when>
                                            <c:when test="${mark*(-1) == (-5)}"> </c:when>
                                        </c:choose>
                                    </option>
                                </c:forEach>
                            </select>
                        </td>
                        <td>
                            <input type="number" step="2" name="respect" min="0" max="200" value="${grade.respect}"/>
                        </td>
                        <td>
                            <input type="number" step="2" name="direspect" min="0" max="200"
                                   value="${grade.direspect}"/>
                        </td>
                    </c:forEach>
                </tr>
            </c:forEach>

        </table>
        <input type="checkbox" name="toExpelled" value="null" checked="checked" hidden="hidden"/>
        <input type="hidden" name="semesterNumber" value="${semesterNumber}"/>
        <input name="save" type="submit" value="Сохранить"/>
    </form>
    <input name="backHome" type="button" value="Вернуться" onclick=" location.href= '<c:url value="/summaryreport"/>' ">
</c:if>

<c:if test="${(studentsList.size() eq 0)and(groupsList.size() eq 0)}">
    Список группы пустой!<br>
    <input name="backHome" type="button" value="Вернуться" onclick=" location.href= '<c:url value="/summaryreport"/>' ">
</c:if>

</body>
</html>